package com.study.design.model.structPattern.flyWeight;

import java.util.HashMap;
import java.util.Map;

/**
* @Name: ChessFlyWeightFactory
* @Description: 享元工厂类：创建并管理享元对象，享元池一般设计成键-值对的形式
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-2-15 下午2:48:51 
* @Version: V1.0
 */
public class ChessFlyWeightFactory {
	
	//享元对象池
	private static Map<String, ChessFlyWeight> map = new HashMap<String, ChessFlyWeight>() ;
	
	/**
	* @Name: getChess
	* @Description: 根据指定的颜色，获取享元对象
	* @Author: 李超	lc_jack@foxmail.com
	* @Version: V1.0
	* @CreateDate: 2017-2-15 下午2:51:29
	* @Parameters: @param color 棋子颜色
	* @Parameters: @return
	* @Return: ChessFlyWeight 返回享元对象
	 */
	public static ChessFlyWeight getChess(String color) {
		if(map.get(color) != null) {
			return map.get(color) ;
		} else {
			ChessFlyWeight cfw = new ConcreteChess(color) ;
			map.put(color, cfw) ;
			return cfw ;
		}
	} 
	

}
